package com.linzp.bishe.controller;

import com.linzp.bishe.common.Result;
import com.linzp.bishe.entity.Accounts;
import com.linzp.bishe.service.AccountsService;
import com.linzp.bishe.service.AllElementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName AllController
 * @Description 描述
 * @Author LinZePeng
 * @Date 2022/5/4 16:09
 * @Version 1.0
 */
@RestController
@RequestMapping("/all")
public class AllController {
	@Autowired
	private AccountsService accountsService;
	@Autowired
	private AllElementService allElementService;

	@GetMapping("/number")
	public Result getUserCatalogue(HttpServletRequest httpServletRequest){
		Accounts account = accountsService.checkAccountStatus(httpServletRequest);
		Result success = Result.success();
		List<Integer> list;
		if("管理员".equals(account.getRoles())){
			list = allElementService.getAllCount(false,0);
		}
		else {
			list = allElementService.getAllCount(true,account.getId());
		}
		success.put("items",list);
		return success;
	}
}
